﻿using System;
using UnityEngine;

public class IdleState : SoldierState
{
    public IdleState(SoldierStateManager stateManager) : base(stateManager)//构造函数，继承子类的两个变量
    {
        _stateID = StateID.eStateID_Object_Idle;               //初始化状态ID为站立的ID
    }

    public override void FixedUpdate()
    {
    }

    public override void OnEnter()                           //刚进入状态时主角执行动作
    {
        m_Animator.SetBool("HaveTarget",false);
    }

    public override void ProcessTransition()
    {
        if (m_Model.transform.tag == "ArcherSoldier")
        {
            if (m_NavAgent.isStopped == false)
            {
                m_StateManager.SetTransition(Transition.eTransiton_Object_Run); //调用跃迁函数（参数为跑）
            }
        }
        if (m_soldier.target != null && (m_Model.transform.position - m_soldier.target.transform.position).magnitude > m_soldier.attackRange)
        {
            m_NavAgent.isStopped = false;
            m_StateManager.SetTransition(Transition.eTransiton_Object_Run); //调用跃迁函数（参数为跑）
        }
        else if(m_soldier.target != null && (m_Model.transform.position - m_soldier.target.transform.position).magnitude < m_soldier.attackRange)
        {
            m_StateManager.SetTransition(Transition.eTransiton_Object_Attack); //调用跃迁函数（参数为跑）
        }
        if (m_soldier.currentHP <= 0)
        {
            m_StateManager.SetTransition(Transition.eTransiton_Object_Dead);//调用跃迁函数（参数为死亡）
        }
    }

    public override void OnExit()
    {
        //m_NavAgent.isStopped = false;
    }

    public override void Update()
    {
        throw new NotImplementedException();
    }
}